//
//  main.c
//  C_3 创建小工具
//
//  Created by Robin on 16/3/16.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, const char * argv[]) {
    
    char line[80];
    
    if (argc != 6) {
        fprintf(stderr, "You should give %i arguements\n",argc);
        return 1;
    }
    
    FILE *file_in = fopen("spooy.csv", "r"); // 文件名错误,犯了一个小错误
    FILE *file1   = fopen(argv[2], "w");
    FILE *file2 = fopen(argv[4], "w");
    FILE *file3 = fopen(argv[5], "w");
    
    printf("argv[0] argv[1] argv[2] argv[3] argv[4] argv[5]: %s   %s %s %s %s %s\n",argv[0],argv[1],argv[2],argv[3],argv[4],argv[5]);
    
    
//    fscanf(file_in, "%79[^\n]\n",line);
//        printf("line is %s\n",line);
    
    
    while (fscanf(file_in, "%79[^\n]\n",line) == 1) { // 记得操作数据流是判断操作是否成功
        
        if (strstr(line, argv[1])) {
            fprintf(file1, "%s\n", line);
        }else if (strstr(line, argv[3])){
            fprintf(file2, "%s\n", line);
        }else{
            fprintf(file3, "%s\n",line);
        }
    }
    
    fclose(file1);
    fclose(file2);
    fclose(file3);
    
    return 0;
}
